package com.shide.flow.demo.engine;

import com.shide.flow.demo.core.FlowContext;
import com.shide.flow.demo.core.FlowCreator;
import com.shide.flow.demo.entity.FlowInstance;
import com.shide.flow.demo.entity.FlowProcess;

import java.util.Map;

/**
 * @author yuwg
 */
public class FlowEngineImpl implements FlowEngine {

    protected FlowContext flowContext;

    /**
     * 配置实现类
     *
     * @param flowContext 全局配置类
     * @return 流程引擎
     */
    @Override
    public FlowEngine configure(FlowContext flowContext) {
        this.flowContext = flowContext;
        return this;
    }

    @Override
    public FlowContext getContext() {
        return this.flowContext;
    }

    /**
     * 启动流程实例
     *
     * @param processKey  流程定位key
     * @param flowCreator 流程任务创建者
     * @param args        参数列表
     * @return {@link FlowInstance} 流程实例
     */
    @Override
    public FlowInstance startInstanceByProcessKey(String processKey, FlowCreator flowCreator, Map<String, Object> args) {
        FlowProcess flowProcess =  flowProcessService().getProcessByKey(processKey);
        return this.startProcessInstance(flowProcess, flowCreator, args);
    }

    /**
     * 根据流程对象 启动流程实例
     *
     * @param flowProcess 流程队形
     * @param flowCreator 流程任务创建者
     * @param args        参数列表
     * @return 流程实例
     */
    @Override
    public FlowInstance startProcessInstance(FlowProcess flowProcess, FlowCreator flowCreator, Map<String, Object> args) {
        return null;
    }
}
